package com.cooldatasoft.domain.daoImpl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.cooldatasoft.domain.dao.TaskDao;
import com.cooldatasoft.domain.model.Project;
import com.cooldatasoft.domain.model.Task;
import com.cooldatasoft.domain.model.User;

public class TaskDaoImpl extends GenericDaoImpl<Task, Long> implements TaskDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Task> getTasksToProject(Project project) {
		Criteria reservationCrit = getSession().createCriteria(Task.class);
		reservationCrit.add(Restrictions.eq("project", project));
		
		List<Task> res = reservationCrit.list();
		return (res.size() > 0) ? res : new ArrayList<Task>();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Task> getTasksToUser(User user) {
		Criteria reservationCrit = getSession().createCriteria(Task.class);
		reservationCrit.add(Restrictions.eq("user", user));
		
		List<Task> res = reservationCrit.list();
		return (res.size() > 0) ? res : new ArrayList<Task>();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Task> getTasksOnProjectWithUser(User user, Project project) {
		Criteria reservationCrit = getSession().createCriteria(Task.class);
		reservationCrit.add(Restrictions.eq("user", user));
		reservationCrit.add(Restrictions.eq("project", project));
		
		List<Task> res = reservationCrit.list();
		return (res.size() > 0) ? res : new ArrayList<Task>();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Task> getTasksByTaskStatusOnProject(String taskStatus,
			Project project) {
		Criteria reservationCrit = getSession().createCriteria(Task.class);
		reservationCrit.add(Restrictions.eq("taskStatus", taskStatus));
		reservationCrit.add(Restrictions.eq("project", project));
		
		List<Task> res = reservationCrit.list();
		return (res.size() > 0) ? res : new ArrayList<Task>();
	}
	
	
}
